package com.asktgapp.user.fragment;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.Html;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RatingBar;
import android.widget.TextView;

import com.asktgapp.JGTool.Utils;
import com.asktgapp.R;
import com.asktgapp.application.ApiUtil;
import com.asktgapp.application.Apiservice;
import com.asktgapp.architecture.retrofit.ApiException;
import com.asktgapp.architecture.retrofit.ApiResponseBody;
import com.asktgapp.architecture.rxjava.ExceptionHandle;
import com.asktgapp.base.BaseFragment;
import com.asktgapp.model.EngineerDetailVO;
import com.asktgapp.model.FreeAskSearchVO;
import com.asktgapp.model.IndustryInfoVO;
import com.asktgapp.model.NewEngineerDetailVO;
import com.asktgapp.model.UserEvaluateVO;
import com.asktgapp.modulebase.common.adapter.BaseAdapter;
import com.asktgapp.modulebase.common.adapter.BaseViewHolder;
import com.asktgapp.modulebase.common.util.PreferencesUtil;
import com.asktgapp.modulebase.common.util.Util;
import com.asktgapp.user.activity.AskDetialActivity;
import com.asktgapp.user.activity.EngineerDetailMoreActivity;
import com.asktgapp.user.activity.FastPaymentActivity;
import com.asktgapp.user.activity.FreeAskAnswerDetailActivity;
import com.asktgapp.user.activity.IndustryInfoDetailActivity;
import com.asktgapp.user.activity.PayActivity;
import com.asktgapp.user.activity.PhotoViewActivity;
import com.asktgapp.user.activity.UsedCheckActivity;
import com.asktgapp.utils.ImageDisplayUtil;
import com.asktgapp.widget.LabelLayout;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

import butterknife.ButterKnife;
import butterknife.InjectView;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * 新 工程师详情页面
 */

public class NewEngineerDetailFragment extends BaseFragment {

    @InjectView(R.id.rvDynamic)
    RecyclerView rvDynamic;
    @InjectView(R.id.rvQuestionAndAnswer)
    RecyclerView rvQuestionAndAnswer;
    @InjectView(R.id.rvComment)
    RecyclerView rvComment;
    @InjectView(R.id.noComment)
    TextView noComment;
    @InjectView(R.id.noQuestionAndAnswer)
    TextView noQuestionAndAnswer;
    @InjectView(R.id.noDynamic)
    TextView noDynamic;

    @InjectView(R.id.tv_engineer_tag1)
    ImageView tv_engineer_tag1;
    @InjectView(R.id.llReward)
    LinearLayout llReward;
    @InjectView(R.id.tv_like)
    TextView tv_like;
    @InjectView(R.id.llLike)
    LinearLayout llLike;
    @InjectView(R.id.tvQuickPay)
    TextView tvQuickPay;
    @InjectView(R.id.tv_Ask)
    LinearLayout tv_Ask;
    @InjectView(R.id.homeService)
    LinearLayout homeService;
    @InjectView(R.id.tv_engineer_name)
    TextView tv_engineer_name;
    @InjectView(R.id.tvAddress)
    TextView tvAddress;
    @InjectView(R.id.tvLabel1)
    TextView tvLabel1;
    @InjectView(R.id.tvLabel2)
    TextView tvLabel2;
    @InjectView(R.id.workTime)
    TextView workTime;
    @InjectView(R.id.tv_reason)
    TextView tv_reason;
    @InjectView(R.id.tv_per1)
    TextView tv_per1;
    @InjectView(R.id.iv_engineer)
    ImageView iv_engineer;
    @InjectView(R.id.ivLike)
    ImageView ivLike;
    //+++++++评价筛选开始
    @InjectView(R.id.pjGroup)
    RadioGroup pjGroup;
    //+++++++评价筛选结束

    private String mId;
    private BaseAdapter questionAndAnswerAdapter, dynamicAdapter, commentAdapter;
    private NewEngineerDetailVO bean;
    private boolean isFollow;
    private double mMoney = 0;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        ViewGroup viewGroup = (ViewGroup) inflater.inflate(R.layout.fragment_engineer_detail_new, container, false);
        ButterKnife.inject(this, viewGroup);
        return super.onCreateView(inflater, viewGroup, savedInstanceState);
    }


    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ButterKnife.reset(this);
    }

    @Override
    protected void initView(View rootView) {
        getBaseActivity().setBackNavigationIcon();
        llLike.setOnClickListener(this);
        tv_Ask.setOnClickListener(this);
        homeService.setOnClickListener(this);
        llReward.setOnClickListener(this);
        iv_engineer.setOnClickListener(this);
        tvQuickPay.setOnClickListener(this);
        noComment.setOnClickListener(this);
        noQuestionAndAnswer.setOnClickListener(this);
        noDynamic.setOnClickListener(this);

        mId = getActivity().getIntent().getStringExtra("id");

        tv_Ask.setSelected(true);
        pjGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                switch (checkedId){
                    case R.id.pj1:
                        break;
                    case R.id.pj2:
                        break;
                    case R.id.pj3:
                        break;
                    case R.id.pjAll:
                        break;
                }
            }
        });
        rvComment.setLayoutManager(new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, false));
        rvComment.setNestedScrollingEnabled(false);
        commentAdapter = new BaseAdapter(getActivity()) {
            @Override
            public BaseViewHolder getViewHolder(ViewGroup parent, int viewType) {
                BaseViewHolder holder = new BaseViewHolder(LayoutInflater.from(getActivity()).inflate(R.layout.item_engineer_detail_pj, parent, false),
                        new BaseViewHolder.Callbacks2() {
                            @SuppressLint("ResourceType")
                            @Override
                            public void bind(BaseViewHolder holder, Object data) {
                                if (data instanceof UserEvaluateVO) {
                                    UserEvaluateVO bean = (UserEvaluateVO) data;
                                    ImageView head = holder.getView(R.id.userHead);
                                    RatingBar bar = holder.getView(R.id.rbNumber);
                                    ImageDisplayUtil.loadCircleHeadImage(getActivity(), head, bean.getUserPic());
                                    holder.setText(R.id.userName, bean.getUserName());
                                    Date date = Util.StrToDate(bean.getAddTime(), "yyyy.MM.dd HH:mm:ss");
                                    String timeStr = Utils.getAskTime(date);
                                    holder.setText(R.id.commentTime, timeStr);
                                    String content = bean.getContent();
                                    if(TextUtils.isEmpty(content))
                                        content = "用户没有输入任何内容";
                                    holder.setText(R.id.commentContent,content);
                                    bar.setNumStars(bean.getSpeed());
                                    bar.setRating(bean.getSpeed());
                                    String pj;
                                    if (bean.getSpeed() <= 3) {
                                        pj = " (一般)";
                                    } else if (bean.getSpeed() <=4)
                                        pj =  " (满意)";
                                    else
                                        pj = " (非常满意)";
                                    holder.setText(R.id.tvPingJ, pj);

                                    holder.getView(R.id.engineerHF).setVisibility(View.VISIBLE);
                                    if(!TextUtils.isEmpty(bean.getReplyContent())){
                                        holder.setText(R.id.engineerHF,
                                                Html.fromHtml("<font color=\"#245290\">工程师回复：</font>"
                                                        +bean.getReplyContent()));
                                    }
                                }
                            }

                            @Override
                            public void onItemClick(BaseViewHolder holder, View view, int position) {

                            }
                        });
                return holder;
            }
        };
        rvComment.setAdapter(commentAdapter);


        rvDynamic.setLayoutManager(new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, false));
        rvDynamic.setNestedScrollingEnabled(false);
        dynamicAdapter = new BaseAdapter(getActivity()) {

            @Override
            public int getItemViewType(int position) {
                IndustryInfoVO bean = (IndustryInfoVO) dynamicAdapter.getData().get(position);
                if (bean.getBannerList().size() > 1) {
                    return 20;
                } else {
                    return 10;
                }
            }

            @Override
            public BaseViewHolder getViewHolder(ViewGroup parent, int viewType) {
                BaseViewHolder holder;

                if (viewType == 10) {
                    holder = new BaseViewHolder(LayoutInflater.from(getActivity()).inflate(R.layout.item_industry_information, parent, false), new BaseViewHolder.Callbacks() {
                        @Override
                        public void bind(BaseViewHolder holder, Object data) {
                            ImageView img = holder.getView(R.id.iv_industry_img);
                            TextView title = holder.getView(R.id.tv_industry_title);
                            TextView time = holder.getView(R.id.tv_industry_time);
                            TextView comment = holder.getView(R.id.tv_industry_read_number);
                            TextView like = holder.getView(R.id.tv_industry_like);
                            if (data instanceof IndustryInfoVO) {
                                IndustryInfoVO bean = (IndustryInfoVO) data;
                                ImageDisplayUtil.LoadNetImage(img, getActivity(), bean.getBannerList().get(0));
                                title.setText(bean.getTitle());
                                time.setText(Utils.getDateYMD(bean.getAddTime()));
                                comment.setText(String.valueOf(bean.getTalkNumber()));
                                like.setText(String.valueOf(bean.getLikeNumber()));
                                holder.setText(R.id.lookNumber, bean.getViewNumber());
                            }
                        }

                        @Override
                        public void onItemClick(View view, int position) {
                            IndustryInfoVO bean = (IndustryInfoVO) dynamicAdapter.getData().get(position);
                            Intent intent = new Intent(getActivity(), IndustryInfoDetailActivity.class);
                            intent.putExtra("id", bean.getId());
                            startActivity(intent);
                        }
                    });
                } else {
                    holder = new BaseViewHolder(LayoutInflater.from(getActivity()).inflate(R.layout.item_industry_information_three_image, parent, false), new BaseViewHolder.Callbacks() {
                        @Override
                        public void bind(BaseViewHolder holder, Object data) {

                            TextView title = holder.getView(R.id.tv_industry_title);
                            TextView time = holder.getView(R.id.tv_industry_time);
                            TextView comment = holder.getView(R.id.tv_industry_read_number);
                            TextView like = holder.getView(R.id.tv_industry_like);
                            ImageView ivQuestionImg1 = holder.getView(R.id.ivQuestionImg1);
                            ImageView ivQuestionImg2 = holder.getView(R.id.ivQuestionImg2);
                            ImageView ivQuestionImg3 = holder.getView(R.id.ivQuestionImg3);
                            if (data instanceof IndustryInfoVO) {

                                IndustryInfoVO bean = (IndustryInfoVO) data;

                                if (bean.getBannerList().size() > 2) {
                                    ImageDisplayUtil.LoadNetImage(ivQuestionImg1, getActivity(), bean.getBannerList().get(0));
                                    ImageDisplayUtil.LoadNetImage(ivQuestionImg2, getActivity(), bean.getBannerList().get(1));
                                    ImageDisplayUtil.LoadNetImage(ivQuestionImg3, getActivity(), bean.getBannerList().get(2));
                                } else {
                                    ImageDisplayUtil.LoadNetImage(ivQuestionImg1, getActivity(), bean.getBannerList().get(0));
                                    ImageDisplayUtil.LoadNetImage(ivQuestionImg2, getActivity(), bean.getBannerList().get(1));
                                    ivQuestionImg3.setVisibility(View.GONE);
                                }

                                title.setText(bean.getTitle());
                                time.setText(Utils.getDateYMD(bean.getAddTime()));
//                                comment.setText(String.valueOf(bean.getComment_number()));
//                                like.setText(String.valueOf(bean.getLike_number()));
                                holder.setText(R.id.lookNumber, bean.getViewNumber());
                            }
                        }

                        @Override
                        public void onItemClick(View view, int position) {
                            IndustryInfoVO bean = (IndustryInfoVO) dynamicAdapter.getData().get(position);
                            Intent intent = new Intent(getActivity(), IndustryInfoDetailActivity.class);
                            intent.putExtra("id", bean.getId());
                            startActivity(intent);
                        }
                    });
                }
                return holder;
            }
        };
        rvDynamic.setAdapter(dynamicAdapter);

        questionAndAnswerAdapter = new BaseAdapter(getActivity()) {
            @Override
            public BaseViewHolder getViewHolder(ViewGroup parent, int viewType) {
                BaseViewHolder holder = new BaseViewHolder(LayoutInflater.from(getActivity()).inflate(R.layout.item_free_ask_hot, parent, false),
                        new BaseViewHolder.Callbacks2() {
                            @Override
                            public void bind(BaseViewHolder holder, Object data) {
                                if (data instanceof FreeAskSearchVO) {
                                    final FreeAskSearchVO bean = (FreeAskSearchVO) data;
                                    TextView allAnswer = holder.getView(R.id.allAnswer);
                                    ImageView askHead = holder.getView(R.id.iv_head_ask);
//                                    ImageView answerHead = holder.getView(R.id.iv_answer_head);
                                    ImageView ivZan = holder.getView(R.id.ivZan);
                                    ImageView ivQuestionImg1 = holder.getView(R.id.ivQuestionImg1);
                                    ImageView ivQuestionImg2 = holder.getView(R.id.ivQuestionImg2);
                                    ImageView ivQuestionImg3 = holder.getView(R.id.ivQuestionImg3);
                                    LinearLayout llQuestionImg = holder.getView(R.id.llQuestionImg);
                                    ImageDisplayUtil.loadCircleHeadImage(getActivity(), askHead, bean.getUserPic());
                                    holder.setText(R.id.tvAskName, bean.getUsername());
                                    holder.setText(R.id.tvZan, bean.getProblemLikeNum());
                                    holder.setText(R.id.tv_answer, bean.getContent());
                                    if (TextUtils.isEmpty(bean.getLikeId()))
                                        ivZan.setImageResource(R.mipmap.zan_2);
                                    else {
                                        ivZan.setImageResource(R.mipmap.zan_1);
                                    }
                                    if (bean.getIsEngineer().equals("1")) {
                                        holder.getView(R.id.tvCommentType).setVisibility(View.VISIBLE);
                                    } else {
                                        holder.getView(R.id.tvCommentType).setVisibility(View.INVISIBLE);
                                    }
                                    llQuestionImg.setVisibility(View.VISIBLE);
                                    if (bean.getImgList().size() == 1) {
                                        ImageDisplayUtil.LoadASKIMG(ivQuestionImg1, getActivity(), bean.getImgList().get(0));
                                        ivQuestionImg2.setVisibility(View.GONE);
                                        ivQuestionImg3.setVisibility(View.GONE);
                                    } else if (bean.getImgList().size() == 2) {
                                        ImageDisplayUtil.LoadASKIMG(ivQuestionImg1, getActivity(), bean.getImgList().get(0));
                                        ImageDisplayUtil.LoadASKIMG(ivQuestionImg2, getActivity(), bean.getImgList().get(1));
                                        ivQuestionImg3.setVisibility(View.GONE);
                                    } else if (bean.getImgList().size() == 3) {
                                        ImageDisplayUtil.LoadASKIMG(ivQuestionImg1, getActivity(), bean.getImgList().get(0));
                                        ImageDisplayUtil.LoadASKIMG(ivQuestionImg2, getActivity(), bean.getImgList().get(1));
                                        ImageDisplayUtil.LoadASKIMG(ivQuestionImg3, getActivity(), bean.getImgList().get(2));
                                    } else {
                                        llQuestionImg.setVisibility(View.GONE);
                                    }

                                    ivQuestionImg1.setOnClickListener(new View.OnClickListener() {
                                        @Override
                                        public void onClick(View v) {
                                            PhotoViewActivity.statr(getActivity(), 0, (ArrayList<String>) bean.getImgList());
                                        }
                                    });
                                    ivQuestionImg2.setOnClickListener(new View.OnClickListener() {
                                        @Override
                                        public void onClick(View v) {
                                            PhotoViewActivity.statr(getActivity(), 1, (ArrayList<String>) bean.getImgList());
                                        }
                                    });
                                    ivQuestionImg3.setOnClickListener(new View.OnClickListener() {
                                        @Override
                                        public void onClick(View v) {
                                            PhotoViewActivity.statr(getActivity(), 2, (ArrayList<String>) bean.getImgList());
                                        }
                                    });

                                    Date date = Util.StrToDate(bean.getAddTime(), "yyyy.MM.dd HH:mm:ss");
                                    String timeStr = Utils.getAskTime(date);
                                    holder.setText(R.id.addTime, timeStr);

                                    if (bean.getAnswerList().size() > 0) {
                                        holder.getView(R.id.llAnswerComment).setVisibility(View.VISIBLE);
                                        holder.setText(R.id.answerNumber, bean.getAnswerList().size() + " 回复");
//                                        ImageDisplayUtil.loadCircleHeadImage(getActivity(), answerHead, bean.getUserPic());
                                        //判断是否工程师
                                        if (bean.getAnswerList().get(0).getIsProjector().equals("1")) {
                                            holder.getView(R.id.tvCommentType).setVisibility(View.VISIBLE);
                                        } else {
                                            holder.getView(R.id.tvCommentType).setVisibility(View.INVISIBLE);
                                        }
                                        holder.setText(R.id.tvAnswerName, bean.getAnswerList().get(0).getUsername1());
                                        holder.setText(R.id.tvAnswerContent, bean.getAnswerList().get(0).getContent());
                                        if (bean.getAnswerList().size() > 1) {
                                            holder.getView(R.id.llAnswer2).setVisibility(View.VISIBLE);
                                            holder.setText(R.id.tvAnswerName2, bean.getAnswerList().get(1).getUsername1());
                                            holder.setText(R.id.tvAnswerContent2, bean.getAnswerList().get(1).getContent());
                                            //判断是否工程师
                                            if (bean.getAnswerList().get(1).getIsProjector().equals("1")) {
                                                holder.getView(R.id.tvCommentType2).setVisibility(View.VISIBLE);
                                            } else {
                                                holder.getView(R.id.tvCommentType2).setVisibility(View.INVISIBLE);
                                            }
                                        } else {
                                            holder.getView(R.id.llAnswer2).setVisibility(View.GONE);
                                        }

                                    } else {
                                        holder.setText(R.id.answerNumber, "无回复");
                                        holder.getView(R.id.llAnswerComment).setVisibility(View.GONE);
                                    }
                                    allAnswer.setOnClickListener(new View.OnClickListener() {
                                        @Override
                                        public void onClick(View v) {
                                            FreeAskAnswerDetailActivity.startFreeAskAnswerDetailActivty( bean.getId(),getContext());
                                        }
                                    });

                                    holder.getView(R.id.tvAnswerName).setOnClickListener(new View.OnClickListener() {
                                        @Override
                                        public void onClick(View v) {
                                            SkipToEngineerDetail(getActivity(), String.valueOf(bean.getAnswerList().get(0).getId()));
                                        }
                                    });
                                    holder.getView(R.id.zan).setOnClickListener(new View.OnClickListener() {
                                        @Override
                                        public void onClick(View v) {
                                            //点赞接口
                                            if (TextUtils.isEmpty(bean.getLikeId())) {
                                                dealZan(bean.getId(), "1", bean, 3);
                                            } else {
                                                dealZan(bean.getId(), "0", bean, 3);
                                            }
                                            index = questionAndAnswerAdapter.getItemIndex(bean);
                                        }
                                    });
                                }
                            }

                            @Override
                            public void onItemClick(BaseViewHolder holder, View view, int position) {
                                FreeAskSearchVO b = (FreeAskSearchVO) questionAndAnswerAdapter.getData(position);
                                FreeAskAnswerDetailActivity.startFreeAskAnswerDetailActivty(b.getId(),getContext());
                            }
                        });


                return holder;
            }
        };
        rvQuestionAndAnswer.setLayoutManager(new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, false));
        rvQuestionAndAnswer.setNestedScrollingEnabled(false);
        rvQuestionAndAnswer.setAdapter(questionAndAnswerAdapter);
    }


    @Override
    public void loadData() {
        visibleLoading();
        HashMap params = new HashMap();
        params.put("id", mId);
        params.put("page", 1);
        params.put("userId", PreferencesUtil.getString(getActivity(), PreferencesUtil.USER_ID));
        Call<ApiResponseBody<NewEngineerDetailVO>> call = ApiUtil.getInstance().create(Apiservice.class).projecterDetail(params);
        call.enqueue(new Callback<ApiResponseBody<NewEngineerDetailVO>>() {
            @Override
            public void onResponse(Call<ApiResponseBody<NewEngineerDetailVO>> call, Response<ApiResponseBody<NewEngineerDetailVO>> response) {
                inVisibleLoading();
                if (response.isSuccessful()) {
                    bean = response.body().getResult();
                    if (bean != null) {
                        ImageDisplayUtil.loadCircleHeadImage(getActivity(), iv_engineer, bean.getUserPic());
                        if (Util.isEmpty(bean.getRealName()))
                            tv_engineer_name.setText(bean.getUserName());
                        else
                            tv_engineer_name.setText(bean.getRealName());
                        String pro = bean.getProviceName().replaceAll("省", "");
                        String city = bean.getCityName().replaceAll("市", "");
                        if (TextUtils.isEmpty((pro + " " + city).trim()))
                            tvAddress.setText("未知地区");
                        else
                            tvAddress.setText(pro + " " + city);

                        workTime.setText("在线时间：\n" + bean.getOnlineTime());
                        if (!TextUtils.isEmpty(bean.getRecommendReason())) {
                            String[] arr = bean.getRecommendReason().trim().split("##");
                            String recommend = "";
                            for (int i = 0; i < arr.length; i++) {
                                recommend += "★  " + arr[i] + "\n";
                            }
                            tv_reason.setText(recommend);
                        }
                        if (bean.getIsShow() == 1) {
                            tv_engineer_tag1.setVisibility(View.VISIBLE);
                        } else {
                            tv_engineer_tag1.setVisibility(View.INVISIBLE);
                        }
                        if (!TextUtils.isEmpty(bean.getLabel())) {
                            String[] str = bean.getLabel().split(",");
                            if (str.length == 0) {
                                tvLabel1.setVisibility(View.GONE);
                                tvLabel2.setVisibility(View.GONE);
                            } else if (str.length == 1) {
                                if (Util.isEmpty(str[0])) {
                                    tvLabel1.setVisibility(View.GONE);
                                } else {
                                    tvLabel1.setVisibility(View.VISIBLE);
                                }
                                tvLabel2.setVisibility(View.GONE);
                                tvLabel1.setText(str[0]);
                            } else if (str.length >= 2) {
                                tvLabel1.setVisibility(View.VISIBLE);
                                tvLabel2.setVisibility(View.VISIBLE);
                                tvLabel1.setText(str[0]);
                                tvLabel2.setText(str[1]);
                            }
                        } else {
                            tvLabel1.setVisibility(View.GONE);
                            tvLabel2.setVisibility(View.GONE);
                        }


                        tv_per1.setText(bean.getAdvisoryPrice() + "元/次");
                        mMoney = Double.valueOf(bean.getAdvisoryPrice());
                        if (TextUtils.isEmpty(bean.getFollowId())||
                                mId.equals(PreferencesUtil.getString(getActivity(), PreferencesUtil.USER_ID))) {
                            isFollow = false;
                            ivLike.setImageResource(R.mipmap.weiguanzhu);
//                            tv_like.setCompoundDrawablesWithIntrinsicBounds(0, R.mipmap.weiguanzhu, 0, 0);
                            tv_like.setText("未关注 ");
                        } else {
                            isFollow = true;
                            ivLike.setImageResource(R.mipmap.yiguanzh);
//                            tv_like.setCompoundDrawablesWithIntrinsicBounds(0, R.mipmap.yiguanzh, 0, 0);
                            tv_like.setText("已关注");
                        }
                    }
                } else {
                    showTost(response.raw().message(), 1);
                }
            }

            @Override
            public void onFailure(Call<ApiResponseBody<NewEngineerDetailVO>> call, Throwable t) {
                inVisibleLoading();
                visibleNoData();
                ApiException apiException = ExceptionHandle.handleException(t);
                if (apiException.isTokenInvalid()) {
                    showUnLoginSnackbar();
                } else if (apiException.isNetConnected()) {
                    showSetNetworkSnackbar();
                } else {
                    showTost(apiException.getMessage(), 0);
                }

            }
        });
        addSubscription(call);


        HashMap params1 = new HashMap();
        params1.put("page", 1);
        params1.put("userId", mId);
        Call<ApiResponseBody<List<UserEvaluateVO>>> call1 = ApiUtil.getInstance().create(Apiservice.class).selEvaluateList(params1);
        call1.enqueue(new Callback<ApiResponseBody<List<UserEvaluateVO>>>() {
            @Override
            public void onResponse(Call<ApiResponseBody<List<UserEvaluateVO>>> call, Response<ApiResponseBody<List<UserEvaluateVO>>> response) {
                inVisibleLoading();
                if (response.isSuccessful()) {
                    List<UserEvaluateVO> list = response.body().getResult();
                    if (list != null && list.size() > 0) {
                        commentAdapter.setData(list);
                        noComment.setText("查看更多>>");
                    } else {
                        noComment.setText("暂无相关信息");
                    }
                } else {
                    showTost(response.raw().message(), 1);
                }
            }

            @Override
            public void onFailure(Call<ApiResponseBody<List<UserEvaluateVO>>> call, Throwable t) {
                inVisibleLoading();
                visibleNoData();
                ApiException apiException = ExceptionHandle.handleException(t);
                if (apiException.isTokenInvalid()) {
                    showUnLoginSnackbar();
                } else if (apiException.isNetConnected()) {
                    showSetNetworkSnackbar();
                } else {
                    showTost(apiException.getMessage(), 0);
                }

            }
        });
        addSubscription(call1);


        HashMap params2 = new HashMap();
        params2.put("page", 1);
        params2.put("userId", mId);
        Call<ApiResponseBody<List<IndustryInfoVO>>> call2 = ApiUtil.getInstance().create(Apiservice.class).selInformationList(params2);
        call2.enqueue(new Callback<ApiResponseBody<List<IndustryInfoVO>>>() {
            @Override
            public void onResponse(Call<ApiResponseBody<List<IndustryInfoVO>>> call, Response<ApiResponseBody<List<IndustryInfoVO>>> response) {
                inVisibleLoading();

                if (response.isSuccessful()) {
                    List<IndustryInfoVO> list = response.body().getResult();
                    if (list != null && list.size() > 0) {
                        dynamicAdapter.setData(list);
                        noDynamic.setText("查看更多>>");
                    } else
                        noDynamic.setText("暂无相关信息");
                } else {
                    showTost(response.raw().message(), 1);
                }
            }

            @Override
            public void onFailure(Call<ApiResponseBody<List<IndustryInfoVO>>> call, Throwable t) {
                inVisibleLoading();
                visibleNoData();
                ApiException apiException = ExceptionHandle.handleException(t);
                if (apiException.isTokenInvalid()) {
                    showUnLoginSnackbar();
                } else if (apiException.isNetConnected()) {
                    showSetNetworkSnackbar();
                } else {
                    showTost(apiException.getMessage(), 0);
                }

            }
        });
        addSubscription(call2);


        HashMap params3 = new HashMap();
        params3.put("userId", mId);
        params3.put("page", 1);
        params3.put("type", 1);
        params3.put("isEngineer", 1);

        Apiservice apiservice = ApiUtil.getInstance().create();
        Call<ApiResponseBody<List<FreeAskSearchVO>>> call3 = apiservice.selMyProblemList(params3);
        call3.enqueue(new Callback<ApiResponseBody<List<FreeAskSearchVO>>>() {
            @Override
            public void onResponse(Call<ApiResponseBody<List<FreeAskSearchVO>>> call, Response<ApiResponseBody<List<FreeAskSearchVO>>> response) {
                inVisibleLoading();
                if (response.isSuccessful()) {
                    List<FreeAskSearchVO> list = response.body().getResult();
                    List<FreeAskSearchVO> showList = new ArrayList<>();
                    if (list == null) {
                        noQuestionAndAnswer.setText("暂无相关信息");
                        return;
                    }
                    if (list.size() > 2) {
                        showList.add(list.get(0));
                        showList.add(list.get(1));
                    } else {
                        showList.addAll(list);
                    }
                    noQuestionAndAnswer.setText("查看更多>>");
                    questionAndAnswerAdapter.setData(showList);
                }
            }

            @Override
            public void onFailure(Call<ApiResponseBody<List<FreeAskSearchVO>>> call, Throwable t) {
                inVisibleLoading();
                ApiException apiException = ExceptionHandle.handleException(t);
                if (apiException.isTokenInvalid()) {
                    showUnLoginSnackbar();
                } else if (apiException.isNetConnected()) {
                    showSetNetworkSnackbar();
                } else {
                    showTost(apiException.getMessage(), 0);
                }

            }
        });
        addSubscription(call3);
    }

    private int index = -1;

    //点赞接口
    private void dealZan(String id, final String temp, final FreeAskSearchVO bean, int type) {
        if (Util.isEmpty(PreferencesUtil.getString(getActivity(), PreferencesUtil.USER_ID))) {
            showTost("未登录，不能点赞！请先登录", 1);
            return;
        }
        Apiservice apiservice = ApiUtil.getInstance().create();
        HashMap params = new HashMap();

        params.put("temp", temp);
        params.put("type", type);
        params.put("id", id);
        params.put("userid", PreferencesUtil.getString(getActivity(), PreferencesUtil.USER_ID));
//        showProgress(getClass().getSimpleName());
        Call<ApiResponseBody> call = apiservice.doLike(params);
        call.enqueue(new Callback<ApiResponseBody>() {
            @Override
            public void onResponse(Call<ApiResponseBody> call, Response<ApiResponseBody> response) {
//                dismissProgress();
                if (response.isSuccessful()) {
                    int num = Integer.valueOf(bean.getProblemLikeNum());
                    if (temp.equals("1")) {
                        num++;
                        bean.setLikeId("13");
                    } else {
                        num--;
                        bean.setLikeId(null);
                    }
                    bean.setProblemLikeNum(String.valueOf(num));
                    questionAndAnswerAdapter.update(bean, index);
                } else {
                    showTost(response.raw().message(), 0);
                }
            }

            @Override
            public void onFailure(Call<ApiResponseBody> call, Throwable t) {
//                dismissProgress();
                ApiException exception = ExceptionHandle.handleException(t);
                if (exception.isTokenInvalid()) {
                    showUnLoginSnackbar();
                } else if (exception.isNetConnected()) {
                    showSetNetworkSnackbar();
                } else {
                    showTost(exception.getMessage(), 1);
                }
            }
        });

    }

    @Override
    public void onClick(View v) {
        super.onClick(v);
        if (checkIsLogin("登录后可体验更多内容")) {
            switch (v.getId()) {
                case R.id.llLike:
                    // 0取消关注 1关注
                    if (isFollow) {
                        doFollow(0);
                    } else {
                        doFollow(1);
                    }
                    break;
                case R.id.tv_Ask:

                    tv_Ask.setSelected(true);
                    homeService.setSelected(false);
                    tvQuickPay.setText("立即咨询");

                    break;
                case R.id.homeService:
                    tv_Ask.setSelected(false);
                    homeService.setSelected(true);
                    tvQuickPay.setText("提交服务");
                    break;

                case R.id.tvQuickPay:
                    if(tv_Ask.isSelected()){
                        if (PreferencesUtil.getBoolean(getActivity(), PreferencesUtil.KEY_IS_ENGINEER)) {
                            showTost("您已是工程师,目前不能咨询他人", 1);
                            return;
                        }
                        Intent intent = new Intent(getActivity(), PayActivity.class);
                        intent.putExtra("type", 0);
                        intent.putExtra("eg_user_id", String.valueOf(bean.getId()));
                        intent.putExtra("money", mMoney);
                        intent.putExtra("name", bean.getRealName());
                        intent.putExtra("eg_pic", bean.getUserPic());
                        startActivity(intent);
                    }else {
                        if (mId.equals(PreferencesUtil.getString(getActivity(), PreferencesUtil.USER_ID))) {
                            showTost("不能向自己发布上门服务", 0);
                            return;
                        }
//                        NewEngineerDetailVO bean = (NewEngineerDetailVO) getBaseActivity().getIntent().getSerializableExtra("bean");
//                        Intent pay = new Intent(getActivity(), FastPaymentActivity.class);
//                        FreeAskSearchVO.AnswerListBean answerBean = new FreeAskSearchVO.AnswerListBean();
//                        answerBean.setUsername1(bean.getRealName());
//                        answerBean.setUserPic1(bean.getUserPic());
//                        answerBean.setAuserId(mId);
//                        pay.putExtra("receivables", answerBean);
//                        pay.putExtra("isReward", false);
//                        pay.putExtra("label", bean.getLabel());
//                        pay.putExtra("bean",bean);
//                        startActivity(pay);
                        Intent intent1 = new Intent(getActivity(), UsedCheckActivity.class);
                        intent1.putExtra("id", mId);
                        intent1.putExtra("bean",bean);
                        startActivity(intent1);
                    }

                    break;
                case R.id.llReward:
                    if (mId.equals(PreferencesUtil.getString(getActivity(), PreferencesUtil.USER_ID))) {
                        showTost("不能向自己送心意", 0);
                        return;
                    }
                    Intent reward = new Intent(getActivity(), FastPaymentActivity.class);
                    FreeAskSearchVO.AnswerListBean answerListBean = new FreeAskSearchVO.AnswerListBean();
                    answerListBean.setUsername1(bean.getRealName());
                    answerListBean.setUserPic1(bean.getUserPic());
                    answerListBean.setAuserId(mId);
                    reward.putExtra("receivables", answerListBean);
                    reward.putExtra("isReward", true);
                    reward.putExtra("label", bean.getLabel());
                    startActivity(reward);
                    break;
                case R.id.iv_engineer:
                    seeBigPic(0, bean.getUserPic());
                    break;

                case R.id.noComment:
                    if (noComment.getText().toString().equals("查看更多>>")) {
                        Intent intent2 = new Intent(getActivity(), EngineerDetailMoreActivity.class);
                        intent2.putExtra("engineerId", mId);
                        intent2.putExtra("type", 0);
                        startActivity(intent2);
                    }
                    break;
                case R.id.noDynamic:
                    if (noDynamic.getText().toString().equals("查看更多>>")) {
                        Intent intent2 = new Intent(getActivity(), EngineerDetailMoreActivity.class);
                        intent2.putExtra("engineerId", mId);
                        intent2.putExtra("type", 1);
                        startActivity(intent2);
                    }
                    break;
                case R.id.noQuestionAndAnswer:
                    if (noQuestionAndAnswer.getText().toString().equals("查看更多>>")) {
                        Intent intent2 = new Intent(getActivity(), EngineerDetailMoreActivity.class);
                        intent2.putExtra("engineerId", mId);
                        intent2.putExtra("type", 2);
                        startActivity(intent2);
                    }
                    break;
            }
        }
    }

    private void doFollow(int i) {
        if (checkIsLogin("登录后可体验更多内容")) {

            if (mId.equals(PreferencesUtil.getString(getActivity(), PreferencesUtil.USER_ID))) {
                showTost("不能关注自己", 0);
                return;
            }

            Apiservice apiservice = ApiUtil.getInstance().create();
            HashMap params = new HashMap();
            params.put("userid", PreferencesUtil.getString(getActivity(), PreferencesUtil.USER_ID));
            //0:二手机 1:设备出租 2:设备求租 3:工程师
            params.put("type", 3);
            params.put("temp", i);
            params.put("id", mId);
            showProgress(getClass().getSimpleName());
            Call<ApiResponseBody> call = apiservice.follow(params);
            call.enqueue(new Callback<ApiResponseBody>() {
                @Override
                public void onResponse(Call<ApiResponseBody> call, Response<ApiResponseBody> response) {
                    dismissProgress();
                    if (response.isSuccessful()) {
                        if (isFollow) {
                            ivLike.setImageResource(R.mipmap.weiguanzhu);
//                        tv_like.setCompoundDrawablesWithIntrinsicBounds(0, R.mipmap.weiguanzhu, 0, 0);
                            tv_like.setText("未关注 ");
                        } else {
                            ivLike.setImageResource(R.mipmap.yiguanzh);
//                        tv_like.setCompoundDrawablesWithIntrinsicBounds(0, R.mipmap.yiguanzh, 0, 0);
                            tv_like.setText("已关注");
                        }
                        isFollow = !isFollow;
                    } else {
                        showTost(response.raw().message(), 1);
                    }
                }

                @Override
                public void onFailure(Call<ApiResponseBody> call, Throwable t) {
                    dismissProgress();
                    ApiException apiException = ExceptionHandle.handleException(t);
                    if (apiException.isTokenInvalid()) {
                        showUnLoginSnackbar();
                    } else if (apiException.isNetConnected()) {
                        showSetNetworkSnackbar();
                    } else {
                        showTost(apiException.getMessage(), 0);
                    }
                }
            });
        }
    }


}
